package com.xcdh.ittools.utils;

import com.api.ittools.entity.ToolDatasource;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;

import java.util.function.Supplier;

/**
 * DataSourceChange
 * Created by wjg on 2024/4/9.
 */
public class DataSourceChange {

    public static <T> T switchDatasource(String ds , Supplier<T> tSupplier){
        DynamicDataSourceContextHolder.push(ds);
        try {
            return tSupplier.get() ;
        }finally {
            DynamicDataSourceContextHolder.poll();
        }
    }
}
